home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS2.ZIP / RNEWS / RNEWS.C < prev    next >
C/C++ Source or Header  |  1993-09-27  |  50KB  |  1,415 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    r n e w s . c                                                   */
  3. /*                                                                    */
  4. /*    Receive incoming news into the news directory.                  */
  5. /*                                                                    */
  6. /*    Written by Mike Lipsie; modified for UUPC/extended 1.11s by     */
  7. /*    Andrew H., Derbyshire.                                          */
  8. /*                                                                    */
  9. /*    Changes and Compilation Copyright (c) 1992 by Andrew H.         */
  10. /*    Derbyshire.  All rights reserved except as granted by the       */
  11. /*    general UUPC/extended license.                                  */
  12. /*                                                                    */
  13. /*    This package has been substantially modified.  It will now      */
  14. /*    copy compressed articles (assumed batches but they could be     */
  15. /*    single articles) to the CMPRSSED directory and it will          */
  16. /*    unbatch (if necessary) and deliver articles to their            */
  17. /*    appropriate newsgroup directories.  At the end, if the file     */
  18. /*    was compressed it will invoke a batch file which will           */
  19. /*    uncompress the file and then feed it back to rnews.             */
  20. /*                                                                    */
  21. /*    Appropriate is defined as                                       */
  22. /*                                                                    */
  23. /*       (a) the newsgroup is in the active file and                  */
  24. /*       (b) the directory name is the group name with all            */
  25. /*           the"."s replaced with "/"s and all of that under the     */
  26. /*           news directory.                                          */
  27. /*                                                                    */
  28. /*    Names are insured to be valid by ImportNewsGroup, which maps    */
  29. /*    invalid characters and truncates names as required.             */
  30. /*--------------------------------------------------------------------*/
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                          RCS Information                           */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. /*
  37.  *       $Id: rnews.c 1.17 1993/09/27 04:04:06 ahd Exp $
  38.  *
  39.  *       $Log: rnews.c $
  40.  * Revision 1.17  1993/09/27  04:04:06  ahd
  41.  * Reduce buffer sizes to avoid 16 bit stack over flows
  42.  *
  43.  * Revision 1.16  1993/09/24  03:43:27  ahd
  44.  * Double buffers to avoid crashes during Disney Stock Flame War
  45.  *
  46.  * Revision 1.15  1993/09/21  01:42:13  ahd
  47.  * Suppress changes to body of delivered news
  48.  *
  49.  * Revision 1.14  1993/09/20  04:41:54  ahd
  50.  * OS/2 2.x support
  51.  *
  52.  * Revision 1.13  1993/07/31  16:26:01  ahd
  53.  * Changes in support of Robert Denny's Windows support
  54.  *
  55.  * Revision 1.12  1993/07/22  23:19:50  ahd
  56.  * First pass for Robert Denny's Windows 3.x support changes
  57.  *
  58.  * Revision 1.11  1993/05/03  02:41:57  ahd
  59.  * Correct name of file to set into binary mode
  60.  *
  61.  * Revision 1.10  1993/04/19  13:16:20  ahd
  62.  * Binary mode for snews
  63.  *
  64.  * Revision 1.9  1993/04/17  13:40:39  ahd
  65.  * fix compile errors for snews fix
  66.  *
  67.  * Revision 1.8  1993/04/17  13:23:37  ahd
  68.  * make snews option more compatible with snews (which is brain dead)
  69.  *
  70.  * Revision 1.7  1993/04/16  12:55:36  dmwatt
  71.  * Bounds check group lengths
  72.  *
  73.  * Revision 1.5  1993/04/11  00:33:54  ahd
  74.  * Global edits for year, TEXT, etc.
  75.  *
  76.  * Revision 1.4  1993/03/24  01:57:30  ahd
  77.  * Corrections for short articles
  78.  * Corrections for articles claimed to be zero length
  79.  * Resync gracefully after incorrect length descriptor
  80.  *
  81.  * Revision 1.3  1993/03/06  23:04:54  ahd
  82.  * Do not delete open files
  83.  *
  84.  * Revision 1.2  1992/11/22  21:14:21  ahd
  85.  * Reformat selected sections of code
  86.  * Check for premature end of articles in batched news
  87.  *
  88.  */
  89.  
  90. static const char rcsid[] =
  91.          "$Id: rnews.c 1.17 1993/09/27 04:04:06 ahd Exp $";
  92.  
  93. /*--------------------------------------------------------------------*/
  94. /*                        System include files                        */
  95. /*--------------------------------------------------------------------*/
  96.  
  97. #include <stdio.h>
  98. #include <stdlib.h>
  99. #include <string.h>
  100. #include <ctype.h>
  101. #include <time.h>
  102. #include <fcntl.h>
  103. #include <io.h>
  104. #include <process.h>
  105.  
  106. /*--------------------------------------------------------------------*/
  107. /*                    UUPC/extended include files                     */
  108. /*--------------------------------------------------------------------*/
  109.  
  110. #include "lib.h"
  111. #include "active.h"
  112. #include "getopt.h"
  113. #include "getseq.h"
  114. #include "history.h"
  115. #include "hlib.h"
  116. #include "import.h"
  117. #include "importng.h"
  118. #include "logger.h"
  119. #include "timestmp.h"
  120.  
  121. #include "execute.h"
  122.  
  123. /*--------------------------------------------------------------------*/
  124. /*                           Global defines                           */
  125. /*--------------------------------------------------------------------*/
  126.  
  127. #define UNCOMPRESS "uncompre"
  128. #ifdef BIT32ENV
  129. #define DISNEY (BUFSIZ*2)
  130. #else
  131. #define DISNEY (BUFSIZ*4/3)
  132. #endif
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*                          Global variables                          */
  136. /*--------------------------------------------------------------------*/
  137.  
  138. currentfile();
  139.  
  140. extern struct grp *group_list;   /* List of all groups */
  141.  
  142. FILE *hfile = NULL;           /* History file */
  143. char history_date[12];        /* dd/mm/yyyy + null + 1 for no good reason */
  144.  
  145. /*--------------------------------------------------------------------*/
  146. /*                       Functions in this file                       */
  147. /*--------------------------------------------------------------------*/
  148.  
  149. static boolean deliver_article(char *art_fname);
  150.                               /* Distribute the article to the
  151.                                  proper newsgroups                   */
  152.  
  153. static void copy_file(FILE *f,
  154.             char *group,
  155.             char *xref);      /* Copy file (f) to newsgroup          */
  156.  
  157. static struct grp *find_newsgroup(const char *grp);
  158.                               /* Get the grp struct for the newsgroup */
  159.  
  160. static void get_snum(const char *group, char *snum);
  161.                                     /* Get (and format) the next article
  162.                                        number in group                     */
  163.  
  164. static void fixEOF( char *buf, int bytes );
  165.  
  166. static int Single( char *filename , FILE *stream );
  167.  
  168. static int Compressed( char *filename , FILE *in_stream );
  169.  
  170. static int Batched( char *filename, FILE *stream);
  171.  
  172. static void xmit_news( char *sysname, FILE *in_stream );
  173.  
  174. static int copy_snews( char *filename, FILE *stream );
  175.  
  176. /*--------------------------------------------------------------------*/
  177. /*    m a i n                                                         */
  178. /*                                                                    */
  179. /*    Main program                                                    */
  180. /*                                                                    */
  181. /*    Exit conditions                                                 */
  182. /*                                                                    */
  183. /*    0 - Success                                                     */
  184. /*    1 - System configuration failed                                 */
  185. /*    2 - Unable to open working file                                 */
  186. /*    4 - out of memory                                               */
  187. /*    5 - Unable to create history dbm file                           */
  188. /*    6 - Problem decompressing news batch                            */
  189. /*    7 - Unable to create cmprssed directory                         */
  190. /*--------------------------------------------------------------------*/
  191.  
  192. void main( int argc, char **argv)
  193. {